package com.richapp.launcher.scene.conditions.time;

import android.util.Log;

import com.richapp.launcher.database.system.dao.SceneModelDao;
import com.richapp.launcher.database.system.mode.SceneModel;
import com.richapp.launcher.scene.SceneServer;
import com.richapp.launcher.scene.abstracts.SceneAbstractTimeConditions;
import com.richapp.launcher.scene.interfaces.ISceneConditions;
import com.richapp.launcher.scene.interfaces.ISceneTimeConditions;

public class SceneTimeAgingConditions extends SceneAbstractTimeConditions {

	private long startTime;
	private long stopTime;
	
	public SceneTimeAgingConditions() {
		
	}

	@Override
	public int getConditionType() {
		return ISceneConditions.SCENE_CONDITION_TYPE_TIME;
	}

	@Override
	public int getConditionSubType() {
		return ISceneTimeConditions.SCENE_CONDITION_SUB_TYPE_TIME_AGING;
	}
	
	public long getStartTime() {
		return startTime;
	}

	public void setStartTime(long startTime) {
		this.startTime = startTime;
	}

	public long getStopTime() {
		return stopTime;
	}

	public void setStopTime(long stopTime) {
		this.stopTime = stopTime;
	}

	@Override
	public boolean checkCondition(String sceneName) {
		SceneModel sceneModel = new SceneModel();
		SceneModelDao sceneModelDao = new SceneModelDao(SceneServer.getInstance().getContext());
		sceneModel=sceneModelDao.getSceneModelOnly(sceneName);
		long currentTime = System.currentTimeMillis();
		if(startTime < currentTime && stopTime > currentTime && "true".equals(sceneModel.getStatusCycleFlag())){
            /*Log.v("TEST", "currentTime:" + currentTime);
            Log.v("TEST","startTime:"+startTime);
            Log.v("TEST","stopTime:"+stopTime);*/
			return true;
		}else if (currentTime > stopTime ){
			sceneModel.setStatusCycleFlag("true");
			sceneModelDao.add(sceneModel);
		}
		return false;
	}
}
